package cn.cau.service.impl;

import cn.cau.dao.CategoryDao;
import cn.cau.entity.*;
import cn.cau.service.QrcodeService;
import cn.cau.utils.QRCodeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class QrcodeServiceImpl implements QrcodeService {
    @Autowired
    CategoryDao categoryDao;
    @Override
    public Qrcode generateQrcode(CodeRule codeRule,
                                 String ruleCategoryName,
                                 String categoryName,
                                 List<String> categoryOptionsDetials,
                                 List<String> categoryOptions,
                                 String userName,
                                 String projectPath){
        String qrtext="生成用户:"+userName+"\n"+
                        "规则:"+codeRule.getCodeRuleName()+"\n"+
                        "规则库:"+ruleCategoryName+"\n"+
                        "种类:"+categoryName+"\n";
        for (int i = 0; i < categoryOptions.size(); i++) {
            String categoryOption=(String) categoryOptions.get(i);
            String categoryOptionDetial=(String) categoryOptionsDetials.get(i);
            qrtext+=categoryOptionDetial+":"+categoryOption+"\n";
        }
        Qrcode qrcode=new Qrcode();
        qrcode.setPath(new QRCodeUtil().generateQrcode(qrtext,codeRule.getCodeRuleId()+"_"+System.currentTimeMillis()+".jpg",projectPath));
        return qrcode;
    }
}
